package com.fll.fangyitask.service.impl;

import com.fll.fangyicommon.entity.task.Learn;
import com.fll.fangyitask.dao.LearnDao;
import com.fll.fangyitask.service.LearnService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author fll
 * create 2023/3/12
 */
@Service
@Slf4j
public class LearnServiceImpl implements LearnService {

    @Autowired
    private LearnDao learnDao;

    @Override
    public Integer insert(Learn learn) {
        Integer num = learnDao.insert(learn);
        if (num != 0){
            log.info("学习成功，插入学习记录表===>{}条数据", num);
            return num;
        }
        log.error("学习失败");
        return -1;
    }

    /**
     * 根据userId和taskId判断学学习记录是否存在
     * @param userId
     * @param taskId
     * @return
     */
    @Override
    public Boolean isExist(Integer userId, Integer taskId){
        Learn learn = learnDao.isExist(userId, taskId);
        if (learn != null){
            return true;
        }
        return false;
    }

    /**
     * 学习记录存在时再次学习更新学习时间
     * @param learn
     * @return
     */
    public Integer update(Learn learn){
        Integer num = learnDao.update(learn);
        if (num != 0){
//            log.info("更新learn学习记录成功");
            return num;
        }
//        log.error("更新learn学习记录失败");
        return -1;
    }

    @Override
    public List<Learn> getLearn(Map<String, Object> learnParam){
        List<Learn> learn = learnDao.getLearn(learnParam);
        if (learn != null && learn.size() != 0){
            log.info("根据taskId查询learn记录成功");
            return learn;
        }
        log.warn("根据taskId查询learn记录，为空");
        return null;
    }

}
